home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / welstead / tstmain.cpp < prev   
C/C++ Source or Header  |  1995-05-20  |  4KB  |  145 lines

  1. // TSTMAIN.CPP Test Program for Data Object List Dialog
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include "cwdlg.h"
  6. #include "cwdialgs.h"
  7. #include "dlgids.h"
  8. #include "tssetlst.h"
  9.  
  10. int init_item = 1;
  11.  
  12. setup_record g_setup;
  13. tlist_box_data g_list_data;
  14.  
  15. LRESULT CALLBACK _export WndProc(HWND hWnd,
  16.     UINT message,WPARAM wParam, LPARAM lParam);
  17.  
  18. int WINAPI WinMain(HINSTANCE hInstance,
  19.     HINSTANCE hPrevInstance, LPSTR,int nCmdShow){
  20.     char AppName[]="DataListDlg";
  21.     char MenuName[] = "DialogTestMenu";
  22.     // Get full screen size dimensions:
  23.     int i,xScreen = GetSystemMetrics(SM_CXSCREEN), 
  24.         yScreen = GetSystemMetrics(SM_CYSCREEN);
  25.     
  26.     HWND hWnd;
  27.     MSG msg;
  28.     gdlg_instance = hInstance; //used by uwdialgs.cpp
  29.     WNDCLASS wndclass;
  30.  
  31.     if (!hPrevInstance) {
  32.            wndclass.style       = CS_HREDRAW|CS_VREDRAW;
  33.        wndclass.lpfnWndProc   = WndProc;
  34.        wndclass.cbClsExtra    = 0;
  35.        wndclass.cbWndExtra    = 0;
  36.       wndclass.hInstance     = hInstance ;
  37.     wndclass.hIcon         =
  38.         LoadIcon (NULL,IDI_APPLICATION) ;
  39.     wndclass.hCursor       =
  40.         LoadCursor (NULL, IDC_ARROW) ;
  41.     wndclass.hbrBackground =
  42.         (HBRUSH)GetStockObject(WHITE_BRUSH);
  43.        wndclass.lpszMenuName  = MenuName;
  44.     wndclass.lpszClassName = AppName;
  45.         if (!RegisterClass(&wndclass)) return FALSE;
  46.     }
  47.     hWnd = CreateWindow(AppName,
  48.     "Data Object List Dialog Test",
  49.     WS_OVERLAPPEDWINDOW,0,0,xScreen,yScreen,
  50.     NULL,NULL,hInstance,NULL);
  51.     if (!hWnd) return FALSE;
  52.  
  53.     init_setup (&g_setup);
  54.     g_list_data.item_collection =
  55.         new object_list(MAX_ITEMS);
  56.     g_list_data.selected_item = 1;
  57.     setup_to_collection (&g_setup,
  58.         g_list_data.item_collection);
  59.  
  60.     ShowWindow(hWnd, nCmdShow);
  61.     UpdateWindow(hWnd); 
  62.  
  63.     while (GetMessage(&msg, NULL, 0, 0))     
  64.     {  TranslateMessage(&msg);    
  65.        DispatchMessage(&msg);      
  66.     }
  67.     // Clean up class allocations
  68.     for (i=1;i<=g_list_data.item_collection->
  69.     get_count();i++) 
  70.     delete g_list_data.item_collection->at(i);
  71.     delete g_list_data.item_collection;
  72.  
  73.     return msg.wParam;    
  74. }
  75.  
  76. LRESULT CALLBACK _export WndProc(HWND hWnd,
  77.     UINT message,WPARAM wParam, LPARAM lParam){
  78.    HDC hdc;
  79.    PAINTSTRUCT ps;
  80.    RECT rect;
  81.    HBRUSH hbr;
  82.     tdata_list_dialog *the_dialog;
  83.    // used for device-independent line spacing:
  84.    SIZE text_extent;
  85.    int x_start,y_start,rect_y_start,line_spacing;
  86.    int i;
  87.  
  88.    switch (message) 
  89.    {
  90.    case WM_DESTROY:
  91.       PostQuitMessage(0); break;
  92.    case WM_COMMAND:
  93.       switch (wParam) {
  94.       case IDM_DIALOG:
  95.        the_dialog = new tdata_list_dialog
  96.           (hWnd,"Test Data List Dialog",
  97.           "Select Item:",&g_list_data,init_item);
  98.        the_dialog->exec_dialog ();
  99.            delete the_dialog;
  100.            InvalidateRect(hWnd,NULL,TRUE);
  101.            UpdateWindow(hWnd);
  102.            break;
  103.        case IDM_EXIT:           // Exit the program
  104.       SendMessage (hWnd, WM_CLOSE, 0, 0L) ;
  105.       break ;
  106.       }  // end switch
  107.       break;
  108.    case WM_PAINT:
  109.       hdc = BeginPaint(hWnd,&ps);
  110.       GetTextExtentPoint (hdc,"X",strlen("X"),
  111.         &text_extent);
  112.       line_spacing = 1.5*text_extent.cy;
  113.       y_start = line_spacing;
  114.       rect_y_start = y_start;
  115.       x_start = 5 * text_extent.cx;
  116.       for (i=1;i<=g_list_data.item_collection->
  117.                get_count();i++) { 
  118.       TextOut(hdc,x_start,y_start +
  119.            line_spacing*(i-1),
  120.       ((ttyped_data_obj *)
  121.       (g_list_data.item_collection->at(i)))
  122.           ->get_display_str(),
  123.       strlen (
  124.       ((ttyped_data_obj *)
  125.       (g_list_data.item_collection->at(i)))
  126.           ->get_display_str())
  127.       );
  128.       rect_y_start += line_spacing;
  129.       }
  130.       rect.left = x_start;
  131.       rect.right = rect.left + 10*text_extent.cx;
  132.       rect.top = rect_y_start + line_spacing;
  133.       rect.bottom = rect.top + 2*line_spacing;
  134.       hbr = CreateSolidBrush(g_setup.rect_color);
  135.       FillRect (hdc,&rect,hbr);
  136.       DeleteObject (hbr);
  137.       EndPaint(hWnd,&ps);
  138.       break;
  139.    default:
  140.     return DefWindowProc(hWnd,message,wParam,lParam);
  141.    }
  142.    return 0L;}
  143.  
  144.  
  145.